#include "Http.hpp"
using namespace std;

void Usage(string proc)
{
    cout << "Usage: " << proc << " port" << endl;
}
void LoginService(HttpRequest& req,HttpResponse& resp)
{
    LOG(LogLevel::INFORMATION) << "进入到LoginService";
    string name = "User: ";
  
    string text = name + req.Args() + "\n";
    resp.SetCode(200);
    resp.SetHeader("Content-Type","text/plain");
    resp.SetHeader("Content-Length", to_string(text.size()));
    resp.SetText(text);

}
void RegisterService(HttpRequest& req,HttpResponse& resp)
{
    LOG(LogLevel::INFORMATION) << "进入到RegisterService";
    string name = "User: ";
  
    string text =  name + req.Args()+ "\n";
    resp.SetCode(200);
    resp.SetHeader("Content-Type","text/plain");
    resp.SetHeader("Content-Length", to_string(text.size()));
    resp.SetText(text);

}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERRO);
    }
    uint16_t port = stoi(argv[1]);
    unique_ptr<Http> http_ptr = make_unique<Http>(port);
    http_ptr->HttpService("/login",LoginService);
    http_ptr->HttpService("/register",RegisterService);

    http_ptr->Start();

    return 0;
}